package hello

import (
	"fmt"
	"os"
)

func FormatTest1() {
	fmt.Println("------------ Format Test1() -------------- start.")

	var b bool = true
	n1, n2, n3 := 15, 11, 428
	str := "stringVar"
	gv3 = 34.945 // global var
	gv4 = 22.1 + 34.6i
	n32 := 21 // := 赋值方式 可省略前面的 var , 并自动判断类型

	strFmt := `
  DEC       %%d:%d                     %%04d:%04d       %%-8d:|%-8d| 
  OCT(%d)   %%o:%o     %%#o:%#o         %%04o:%04o       %%8o: |%8o|           
  HEX(%d)  %%x:%x    %%#x:%#x       %%04X:%04X       %%-8x:|%-8x|      
  BIN(%d)   %%b:%b  %%#b:%#b     %%08b:%08b   %%-8b:|%-8b|
  
  科学计数法：%E

  float: %f
  complex: %4f

  float: %g
  complex: %g

  Boolean: %t

  String %%-15s: |%-15s|
  String %%+15s: |%15s|
  String %%s:%s     String %%q:%q    

  Char %%c :%c
  Char %%q :%q
  Unicode:%U    
  
  Value 
  %%v:%v
  %%+v:%+v
  %%#v:%#v
  
  Type %%T: %T 

  指针地址 %%p：%p
  
  参数数组args  长度：%d
`

	// 构造字符串
	result := fmt.Sprintf(strFmt,
		n1, n1, n1,
		n2, n2, n2, n2, n2,
		n3, n3, n3, n3, n3,
		n32, n32, n32, n32, n32,
		12345.6789,
		gv3, gv4,
		gv3, gv4,
		b,
		str, str,
		[]byte("Go语言"), []byte("Go语言"),
		0x4E2D,
		0x4E2D,
		0x4E2D,
		Books{"Go 语言", "www.runoob.com", "Go 语言教程", 6495407},
		Books{"Go 语言", "www.runoob.com", "Go 语言教程", 6495407},
		Books{"Go 语言", "www.runoob.com", "Go 语言教程", 6495407},
		Books{"Go 语言", "www.runoob.com", "Go 语言教程", 6495407},
		&Books{"Go 语言", "www.runoob.com", "Go 语言教程", 6495407},
		len(os.Args),
	)

	fmt.Println(result)

}
